package miniBanco.Mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import miniBanco.Core.Moneda;
import basics.MySqlHelper;

public class MonedaDao {
	MySqlHelper mySqlHelper;
	private static final String TAG = TipoCuentaDao.class.getSimpleName();
	public static final String COLUMNS = "moneda, descripcion";	
	
	MonedaDao()
	{
		mySqlHelper = MySqlHelper.getInstance();
	}
	private StringBuilder findStatement() {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT "+COLUMNS+
				" FROM "+ getTableName()+
				" WHERE moneda = %d ");
		return sb;
	}

	private Moneda doLoad(ResultSet rs) throws SQLException {

		int moneda = rs.getInt(1);
		return Moneda.fromValue(moneda);
		
	}
	protected Moneda getByTipo(int moneda) throws SQLException {
		String sql = findStatement().toString();
		sql = String.format(sql, moneda);
		ResultSet rs = mySqlHelper.ExecuteQuery(sql, TAG);
		rs.next();
		return doLoad(rs);
	}

	protected String getTableName() {
		return "Moneda";
	}
}
